#include <string.h>
#include <stdlib.h>

#include "list.h"
#include "tools.h"

void list_creat(list_node *head)
{
	if ( NULL == head ) {
		xx_dbg("Input para Invalid\n");
		xx_assert(0);
		return;
	}

	head->next = head;
	head->prev = head;
}

void list_add(list_node *head, list_node *new)
{
	if ( NULL == head || NULL == new) {
		xx_dbg("Input para Invalid\n");
		xx_assert(0);
		return;
	}

	head->next->prev = new;
	new->next = head->next;
	new->prev = head;
	head->next = new;
}

void list_dele(list_node *entry)
{
	if ( NULL == entry ) {
		xx_dbg("Input para Invalid\n");
		xx_assert(0);
		return;
	}

	entry->next->prev = entry->prev;
	entry->prev->next = entry->next;
	entry->next = NULL;
	entry->prev = NULL;
}

void list_destroy(list_node *head)
{
	if ( NULL == head ) {
		xx_dbg("Input para Invalid\n");
		xx_assert(0);
		return;
	}

	list_node *ptr = head->next;
	while ( ptr && ptr != head ){
		free(ptr);
		ptr = ptr->next;
	}
}

void list_trav(list_node *head)
{
	if ( NULL == head ) {
		xx_dbg("Input para Invalid\n");
		xx_assert(0);
		return;
	}
	
	list_node *ptr = head->next;
	while ( ptr && ptr != head ){
		ptr = ptr->next;
	}
}

